package com.cloudptt.api.models;

import com.cloudptt.api.comm.CheckData;

import android.os.Parcel;
import android.os.Parcelable;

public class SpeakingInfo implements Parcelable
{
	private static final String key_title = "pttfloornotify";
	private static final String key_AlertType = "AlertType";
	private static final String key_SpeakerNum = "SpeakerNum";
	private static final String key_MemberSpeakTime = "MemberSpeakTime";
	private static final String key_MediaType = "MediaType";
//	private static final String key_End = ";";


//	public static final String key_Not_Acceptable = "-1";
//	public static final String key_Listening = "0";
//	public static final String key_NotSpeak = "1";
//	public static final String key_ISpeak = "2";

	public static final int Type_Not_Acceptable = -1;
	public static final int Type_Listening = 0;
	public static final int Type_NotSpeak = 1;
	public static final int Type_ISpeak = 2;
	
	public static final int Type_VIDEO_START = 0;
	public static final int Type_VIDEO_STOP = 1;
	
	public static final int MEDIATYPE_AUDIO = 0;
	public static final int MEDIATYPE_VIDEO = 1;

	private boolean isInvalid = true;
	private int alertType = Type_Not_Acceptable;
	private String number = "";
	private int memberSpeakTime = 30;


	private int mediaType = MEDIATYPE_AUDIO;

	public SpeakingInfo(String exStr)
	{
		ExtStrInfo info = new ExtStrInfo(exStr);
		String title = info.getTitle();
		if(title != null
				&& key_title.equals(title))
		{
			isInvalid = false;
			String value = info.getValue(key_AlertType);
			alertType = CheckData.parseInt(value);
			number = info.getValue(key_SpeakerNum);
			mediaType = CheckData.parseInt( info.getValue(key_MediaType) );
			if( mediaType == -1 ){
				mediaType = MEDIATYPE_AUDIO;
			}
			
			value = info.getValue(key_MemberSpeakTime);
			memberSpeakTime = CheckData.parseInt(value);
			if(memberSpeakTime == -1)
			{
				memberSpeakTime = 30;
			}
		}
		else
		{
			isInvalid = true;
		}
	}

	public SpeakingInfo()
	{
		alertType = Type_Not_Acceptable;//Ĭ���Լ�˵��
	}

	public boolean isInvalid()
	{
		return isInvalid;
	}


	public int getAlertType() {
		return alertType;
	}

	public void setAlertType(int alertType) {
		this.alertType = alertType;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public int getMediaType() {
		return mediaType;
	}

	public void setMediaType(int mediaType) {
		this.mediaType = mediaType;
	}
	
	public int getMemberSpeakTime() {
		return memberSpeakTime;
	}

	public int describeContents() 
	{
		return 0;
	}

	public void writeToParcel(Parcel out, int flags) {
		out.writeInt(alertType);
		out.writeString(number);
		out.writeInt(memberSpeakTime);
		out.writeInt(mediaType);
	}

	public static final Parcelable.Creator<SpeakingInfo> CREATOR = new Parcelable.Creator<SpeakingInfo>() {
		public SpeakingInfo createFromParcel(Parcel in) {
			return new SpeakingInfo(in);
		}

		public SpeakingInfo[] newArray(int size) {
			return new SpeakingInfo[size];
		}
	};

	private SpeakingInfo(Parcel in) {
		this.alertType = in.readInt();
		this.number = in.readString();
		this.memberSpeakTime = in.readInt();
		this.mediaType = in.readInt();
	}
}
